Skip to content

Conversation

snigdhasjg
Copy link
Contributor

@snigdhasjg snigdhasjg commented Aug 7, 2024

Description

Processes a collection of AWS Systems Manager (SSM) Parameters Store parameters, converting them into a dictionary of strings.

This method supports both JSON-formatted parameters as per JsonParameterProcessor. And plain string & StringList as per DefaultParameterProcessor.

The resulting dictionary keys are case-insensitive, as the other 2 implemenation.

Motivation and Context

We have multiple types of SSM gets loaded during application startup.
Mainly Json and Text based. Params are dynamic in nature, so no way to telling if its Json or Text.

We are using this code for more than a week now, so why not merge it in the lib itself.

Testing

  1. Tested in our net8.0 application already. It runs on official docker image mcr.microsoft.com/dotnet/aspnet:8.0-jammy
  2. Tested in net6.0 locally
  3. Couldn't test on other 2 version for netstandard2.0;netcoreapp3.1 as using ARM

Unit tests have been added, validated.

No impact on existing area as new implementation of the IParameterProcessor

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new tests passed
  • All existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license


namespace Amazon.Extensions.Configuration.SystemsManager
{
public class JsonOrDefaultParameterProcessor : DefaultParameterProcessor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need docs here explaining what this processor does. I would suggest instead of using the term Default here I would use String. So it is obvious to users that this supports either Json or falls back to String if the parameter fails to parse as Json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was thinking that, but then I hold myself cause it's both String and StringList

If you think JsonOrStringParameterProcessor would be good enough I can change that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a valid concern that it is also doing StringList but I feel like String is better then Default. If I read the name JsonOrDefault.. and ignore my knowledge of how things are implemented I would see a name that says Json or some unknown format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah used JsonOrStringParameterProcessor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added docs in places where I felt, open for suggestion

{
foreach (var kv in JsonConfigurationParser.Parse(parameter.Value))
{
var key = !string.IsNullOrEmpty(keyPrefix) ? ConfigurationPath.Combine(keyPrefix, kv.Key) : kv.Key;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you refactor this inner loop logic that is a duplicate inner loop logic in JsonParameterProcessor into a common internal utility method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was thinking on the same line.

I have 3 static methods -
ParseJson can be used in both the new class and json processor.
Other 2 ParseString and ParseStringList can also be extracted out and reused.

Let me work on that

Copy link
Contributor Author

@snigdhasjg snigdhasjg Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted all 3 methods,
refactored both JsonParameterProcessor and DefaultParameterProcessor

Please review

@snigdhasjg
Copy link
Contributor Author

Changes are done from my end. Once reviewed, I'll squash all commits.

@snigdhasjg snigdhasjg requested a review from normj August 12, 2024 18:11
Copy link
Contributor

@peterrsongg peterrsongg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked out the branch, ran the tests myself. Looks good

Passed!  - Failed:     0, Passed:    74, Skipped:     0, Total:    74, Duration: 92 ms - Amazon.Extensions.Configuration.SystemsManager.Tests.dll (netcoreapp3.1)
Test run for C:\Dev\Repos\aws-dotnet-extensions-configuration\test\Amazon.Extensions.Configuration.SystemsManager.Tests\bin\Debug\net6.0\Amazon.Extensions.Configuration.SystemsManager.Tests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.10.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

@snigdhasjg
Copy link
Contributor Author

@normj @peterrsongg have't heard back. any update on this?

@snigdhasjg
Copy link
Contributor Author

@normj any update on this, when can this be merged?

Copy link
Member

@normj normj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologize for the delay. The changes look good but can you add a change file for the release? To do that add a file at .autover/changes/<random-guid>.json with the following content. Feel free to tweak the change log message.

{
  "Projects": [
    {
      "Name": "Amazon.Extensions.Configuration.SystemsManager",
      "Type": "Minor",
      "ChangelogMessages": [
        "Add opt-in JsonOrStringParameterProcessor processor supporting parameters being either strings or JSON"
      ]
    }
  ]
}

@snigdhasjg
Copy link
Contributor Author

@normj rebased and added the file .autover/changes/44bf0928-edf9-4888-aebb-196b6364ffa8.json

@ashishdhingra ashishdhingra requested a review from normj February 20, 2025 18:10
@normj normj changed the base branch from master to dev February 20, 2025 20:54
@normj normj merged commit 6acd0f4 into aws:dev Feb 20, 2025
1 check failed
@normj
Copy link
Member

normj commented Feb 21, 2025

PR was released today as part of version 6.3.0. Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants